
#**
#* Copies the from-File to to-File by invoking the DOS COPY command
#* <p>NOTE:
#* <p>Make sure you use the full path names for both files otherwise
#* you might wonder where the files went.
#* @param from (in) file to be coppied from
#* @param to (in) file to be coppied to
#* @return the RC from the invoked COPY command (0=OK)
#*/

public function AUT_DOS_copy ( in from, in to )
{
	auto cmd = sprintf( "copy \"%s\" \"%s\"", from, to );
	return dos_system( cmd );
}

#**
#*	Initialisiert die AUT
#*	
#*
#* @param usr	(in)	USER
#* @param pwd	(in)	Password
#* @param force	(in)	Auszufhren des erneuten login Ja Nein
#* @return
#*	E_OK:	Erfolg
#*	else:	Fehler
#*/
public function AUT_init ( in usr, in pwd, in force )
{
	auto rc,win;

	if ( force )
	{
		AUT_close();
	}
	else
	{	
	    if ( win_exists ("Flight Reservation Message") == E_OK )
	    {
		    set_window("Flight Reservation Message");
		    button_press("OK");
			rc+= EMOS_set_window ("Flight Reservation", 50);
			return rc;
	    }
	    if ( win_exists ("Flights Table") == E_OK )
	    {
		    set_window("Flights Table");
		    button_press("OK");
			rc+= EMOS_set_window ("Flight Reservation", 50);
			return rc;
	    }
		if ( win_exists ("Flight Reservation") == E_OK )
		{
			rc+= EMOS_set_window ("Flight Reservation", 50);
			return rc;
		}
	    if ( win_exists ("Login") == E_OK )
	    {
		    return AUT_login (usr, pwd);
	    }
	}
	
	AUT_invoke ();
	return AUT_login (usr, pwd);
}


#**
#*	Schliet Flight Reservation
#*/
public function AUT_close ()
{
	if ( win_exists ("Flight Reservation") == E_OK )
	{
		if ( win_close("Flight Reservation") != E_OK )
			AUT_kill();
	}
	if ( win_exists ("Login") == E_OK )
	{
		if ( win_close("Login") != E_OK )
			AUT_kill();
	}
}


#**
#*	Schiet Flight Reservation ab ber Taskmanager
#*
#* 
#*/
public function AUT_kill ()
{
	auto i, rc;
	static proc[] = {
		"Flight Reservation"
	};
	
	load_GUI( GUI_HOME & "\\WinSys.gui" );

	win_activate ("Shell_TrayWnd", RIGHT);
	EMOS_set_window ("Shell_TrayWnd", 11);
	menu_select_item ("Task-Manager...");
	EMOS_set_window ("Windows NT Task-Manager", 3);
	tab_select_item ("tab", "Prozesse"); # Item Number 1;
	for ( i in proc )
	{ 
		set_window ("noname (page)", 2);
		rc = list_select_item ("SysListView32", proc[i]);
		if ( rc == E_OK )
		{
			button_press ("Proze beenden");
			EMOS_set_window ("Warnung vom Task-Manager", 1);
			button_press ("Ja");
		}
	}
	EMOS_set_window ("Windows NT Task-Manager", 3);
	win_close ("Windows NT Task-Manager");
}


#**
#*	Fhrt die Login durch.
#*	
#*
#* @param usr	(in)	USER
#* @param pwd	(in)	Password
#* @return
#*	E_OK:	AUT erfolgreich gestartet
#*	!E_OK:	Fehler
#*/
public function AUT_login ( in usr, in pwd )
{
	auto rc, msg;
	rc = EMOS_set_window ("Login", 60);
	if ( rc == E_OK )
	{
		rc+= edit_set ("AgentsName", usr);
		rc+= edit_set ("Password", pwd);
		rc+= button_press ("OK");
		if ( win_exists ("Flight Reservation Message",20) == E_OK )
		{
			EMOS_set_window ("Flight Reservation Message");
			static_get_text ("Message", msg);
			button_press ("OK");
			tl_step("AUT_login", E_NOT_FOUND, msg &": [user="& usr &", pwd="& pwd &"]" );
			return E_NOT_FOUND;
		}
		rc+= EMOS_set_window( "Flight Reservation", 60 );
	}
	tl_step("AUT_login", rc, "[user="& usr &", pwd="& pwd &"]" );
	return rc;
}


#**
#*	Startet AUT
#*	
#*
#* @return
#*	E_OK:	AUT erfolgreich gestartet
#*	!E_OK:	Fehler
#*/

public function AUT_invoke ()
{
	auto hKey;
	auto homeDir;
	
	hKey = OpenRegistryKey( HKEY_CURRENT_USER, "SOFTWARE;Schueco" );
	homeDir = GetValueData( hKey, "Schuecal2000", "HomeDirectory" );

	return invoke_application( MROOT & "\\samples\\vb\\app\\fltvb41a.exe",
		"",   
	    MROOT & "\\samples\\vb\\app\\", 
	    SW_SHOW );
}

